<?php

use Illuminate\Support\Facades\Route;

Route::get('img/{id}/{w?}/{h?}', 'FileController@image');
Route::get('file/{id}', 'FileController@file');
Route::get('', function () {
    return redirect(admin_url('/index'));
});
Route::group(['namespace' => 'Admin', 'prefix' => 'admin'], function () {

    Route::group(['prefix' => 'public'], function () {
        Route::get('login', 'PublicController@login');
        Route::get('findPass', 'PublicController@findPass');
        Route::post('findPass', 'PublicController@postFindPass');
        Route::post('lang', 'PublicController@lang');
        Route::get('retrievePassword/{code}', 'PublicController@retrievePassword');
        Route::post('retrievePassword', 'PublicController@postRetrievePassword');
        Route::post('logging', 'PublicController@logging');
    });

    Route::group(['middleware' => 'login'], function () {
        Route::group(['prefix' => 'file'], function () {
            Route::post('uploadImage', 'FileController@uploadImage');
            Route::post('uploadFile', 'FileController@uploadFile');
            Route::post('editerImage', 'FileController@editerImage');
        });
        Route::group(['namespace' => 'System', 'prefix' => 'system'], function () {

            /**
             * 用户组
             */
            Route::group(['prefix' => 'group'], function () {
                Route::get('', 'GroupController@index')->middleware('permission');
                Route::get('pager', 'GroupController@pager')->middleware('permission');
                Route::post('permission', 'GroupController@permission')->middleware('permission');
                Route::get('permission_view/{id}', 'GroupController@permission_view')->middleware('permission');
            });

            /**
             * 角色
             */
            Route::group(['prefix' => 'role'], function () {
                crudRoute('RoleController');
                Route::post('permission', 'RoleController@permission')->middleware('permission');
                Route::get('permission_view/{id}', 'RoleController@permission_view')->middleware('permission');
                Route::get('load', 'RoleController@load');
            });

            /**
             * 用户
             */
            Route::group(['prefix' => 'user'], function () {
                crudRoute('UserController');
                Route::get('choose_view', 'UserController@choose_view');
                Route::get('choose', 'UserController@choose');
                Route::get('setPassword/{id}', 'UserController@setPasswordView')->middleware('permission');
                Route::post('setPassword', 'UserController@setPassword');
                Route::post('status/{id}/{status}', 'UserController@status')->middleware('permission');
            });

            /**
             * 医院
             */
            Route::group(['prefix' => 'hospital'], function () {
                crudRoute('HospitalController');
            });

            /**
             * 区域
             */
            Route::group(['prefix' => 'area'], function () {
                crudRoute('AreaController');
                Route::get('load', 'AreaController@load');
            });

            /**
             * 病种
             */
            Route::group(['prefix' => 'department'], function () {
                crudRoute('DepartmentController');
                Route::get('load', 'DepartmentController@load');
            });
        });

        Route::group(['namespace' => 'Ca', 'prefix' => 'ca', 'middleware' => 'hospital'], function () {

            //消费记录
            Route::group(['prefix' => 'promotion'], function () {
                crudRoute('PromotionController');
            });
            /**
             * 来院方式
             */
            Route::group(['prefix' => 'come-way'], function () {
                crudRoute('ComeWayController');
            });

            /**
             * 咨询方式
             */
            Route::group(['prefix' => 'consultation-way'], function () {
                crudRoute('ConsultationWayController');
            });

            /**
             * 病种
             */
            Route::group(['prefix' => 'disease'], function () {
                crudRoute('DiseaseController');
                Route::get('load', 'DiseaseController@load');
            });

            /**
             * 来源
             */
            Route::group(['prefix' => 'source'], function () {
                crudRoute('SourceController');
            });

            /**
             * 医生
             */
            Route::group(['prefix' => 'docker'], function () {
                crudRoute('DockerController');
            });
            
            /**
             * 医生
             */
            Route::group(['prefix' => 'sms-template'], function () {
                crudRoute('SmsTemplateController');
            });


            function buildCustomer($controller)
            {
                crudRoute($controller);
                Route::post('hospitalization', $controller . '@hospitalization')->middleware('permission');
                Route::post('leave-hospital', $controller . '@leaveHospital')->middleware('permission');
                Route::post('arriving', $controller . '@arriving')->middleware('permission');
                Route::post('online-arriving', $controller . '@onlineArriving')->middleware('permission');
                Route::post('loss', $controller . '@loss')->middleware('permission');
                Route::post('visit', $controller . '@visit')->middleware('permission');
                Route::get('export', $controller . '@export')->middleware('permission');
                Route::get('check-mobile', $controller . '@checkMobile');
                Route::get('check-weixin', $controller . '@checkWeixin');
//                Route::get('check-name', $controller . '@checkName');
                Route::get('search-repeat', $controller . '@searchRepeat');
                Route::get('swt/{id}', $controller . '@swt');
                Route::get('detail/{id}', $controller . '@detail');
                Route::post('spend/{id}/{is_spend}', $controller . '@spend')->middleware('permission');
            }

            /**
             * 客户
             */
            Route::group(['prefix' => 'customer'], function () {
                buildCustomer('CustomerController');
            });

            /**
             * 客户
             */
            Route::group(['prefix' => 'day'], function () {
                buildCustomer('DayController');
            });

            /**
             * 客户
             */
            Route::group(['prefix' => 'public'], function () {
                Route::get('', 'PublicController@index')->middleware('permission');
                Route::get('pager', 'PublicController@pager')->middleware('permission');
                Route::post('receive', 'PublicController@receive')->middleware('permission');
            });


            /**
             * 话务领取
             */
            Route::group(['prefix' => 'public-mobile'], function () {
                Route::get('', 'PublicMobileController@index')->middleware('permission');
                Route::get('pager', 'PublicMobileController@pager')->middleware('permission');
                Route::post('receive', 'PublicMobileController@receive')->middleware('permission');
                Route::post('allocation', 'PublicMobileController@allocation')->middleware('permission');
            });

            /**
             * 客户
             */
            Route::group(['prefix' => 'caller'], function () {
                buildCustomer('CallerController');
            });

            /**
             * 客户
             */
            Route::group(['prefix' => 'day-arriving'], function () {
                buildCustomer('DayArrivingController');
            });

            /**
             * 客户
             */
            Route::group(['prefix' => 'tomorrow-arriving'], function () {
                buildCustomer('TomorrowArrivingController');
            });
            /**
             * 回访
             */
            Route::group(['prefix' => 'visit'], function () {
                Route::get('', 'VisitController@index')->middleware('permission');
                Route::get('pager', 'VisitController@pager')->middleware('permission');
                Route::get('annotate/{id}', 'VisitController@annotate')->middleware('permission');
                Route::post('save-annotate', 'VisitController@saveAnnotate')->middleware('permission');
            });

            /**
             * 客户
             */
            Route::group(['prefix' => 'handover-record'], function () {
                Route::get('', 'HandoverRecordController@index')->middleware('permission');
                Route::get('pager', 'HandoverRecordController@pager')->middleware('permission');

                Route::get('caller', 'HandoverRecordController@caller')->middleware('permission');
                Route::post('save-caller', 'HandoverRecordController@saveCaller')->middleware('permission:caller');

                Route::get('custom-service', 'HandoverRecordController@customService')->middleware('permission:customService');
                Route::post('save-custom-service', 'HandoverRecordController@saveCustomService')->middleware('permission:customService');
            });
        });

        Route::group(['namespace' => 'Settings', 'prefix' => 'settings'], function () {

            /**
             * 字典管理
             */
            Route::group(['prefix' => 'code'], function () {
                Route::get('', 'CodeController@index')->middleware('permission');
                Route::get('pager', 'CodeController@pager')->middleware('permission');
            });
            /**
             * 字典值管理
             */
            Route::group(['prefix' => 'code-value'], function () {
                Route::get('pager', 'CodeValueController@pager')->middleware('permission');
                Route::get('create/{code}', 'CodeValueController@create')->middleware('permission');
                Route::get('edit/{id}', 'CodeValueController@edit')->middleware('permission');
                Route::post('save', 'CodeValueController@save')->middleware('permission');
                Route::post('update', 'CodeValueController@update')->middleware('permission');
                Route::post('batchDelete', 'CodeValueController@batchDelete')->middleware('permission');
                Route::post('delete', 'CodeValueController@delete')->middleware('permission');
                Route::get('{code}', 'CodeValueController@index')->middleware('permission');
            });
            /**
             * 审批流程
             */
            Route::group(['prefix' => 'approval-flow'], function () {
                crudRoute('ApprovalFlowController');
            });
        });

        Route::group(['namespace' => 'Log', 'prefix' => 'log'], function () {

            /**
             * 登录日志
             */
            Route::group(['prefix' => 'login'], function () {
                Route::get('', 'LoginController@index')->middleware('permission');
                Route::get('pager', 'LoginController@pager')->middleware('permission');
            });
            /**
             * 操作日志
             */
            Route::group(['prefix' => 'operation'], function () {
                Route::get('', 'OperationController@index')->middleware('permission');
                Route::get('pager', 'OperationController@pager')->middleware('permission');
                Route::get('params/{id}', 'OperationController@params')->middleware('permission:index');
                Route::get('detail/{id}', 'OperationController@detail')->middleware('permission:index');
            });
        });

        Route::group(['namespace' => 'Analysis', 'prefix' => 'analysis'], function () {

            /**
             * 登录日志
             */
            Route::group(['prefix' => 'caller'], function () {
                Route::get('', 'CallerController@index')->middleware('permission');
                Route::get('pager', 'CallerController@pager')->middleware('permission');
                Route::get('effective', 'CallerController@effective')->middleware('permission');
                Route::get('pager_effective', 'CallerController@pager_effective')->middleware('permission');
                Route::get('pager_promotion', 'CallerController@pager_promotion')->middleware('permission');
                Route::get('promotion', 'CallerController@promotion')->middleware('permission');
            });
        });

        Route::group(['prefix' => 'index'], function () {
            Route::get('', 'IndexController@index');
            Route::get('welcome', 'IndexController@welcome');
            Route::get('theme', 'IndexController@theme');
            Route::get('lock_screen', 'IndexController@lock_screen');
            Route::get('baidu', 'IndexController@baidu');
            Route::get('password', 'IndexController@password');
            Route::get('note', 'IndexController@note');
            Route::post('changePassword', 'IndexController@changePassword');
            Route::post('initPassword', 'IndexController@initPassword');
            Route::post('skin', 'IndexController@skin');
            Route::post('hospital', 'IndexController@hospital');
        });


        Route::group(['prefix' => 'console'], function () {
            Route::get('', 'ConsoleController@index')->middleware('hospital');
            Route::get('workplace', 'ConsoleController@workplace');
            Route::get('dashboard', 'ConsoleController@dashboard');
        });

        Route::group(['prefix' => 'setting'], function () {
            Route::get('', 'SettingController@index')->middleware('permission');
            Route::post('save', 'SettingController@save');
        });

        Route::group(['prefix' => 'workbench'], function () {
            Route::get('', 'WorkbenchController@index');
            Route::get('loadMember', 'WorkbenchController@loadMember');
            Route::post('save', 'WorkbenchController@save');
        });
    });
});
